package com.yylany.controller;

import com.yylany.bo.GoodsData;
import com.yylany.bo.GoodsResult;
import com.yylany.enums.ResultEnum;
import com.yylany.service.GoodsService;
import com.yylany.vo.GoodResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description: pinyougou
 *
 * @author <a href="mailto:17777502615@163.com">yaoyonglong</a>
 * @date 2018/12/20
 * @since 1.0.0
 */

@RestController
@RequestMapping
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 条件搜索 商品
     *
     * @param result 对前台传过来的数据进行封装
     * @return
     */
    @GetMapping("/goods")
    public GoodResult getGoods(GoodsResult result) {


        /**
         *   id:"SKUID",
         *                goods_name:"商品名称",
         *                price:"价格",
         *                midlogo:"商品lOGO(130x130)",
         *                comment_count:"评论数"
         */
        List<GoodsData> goods = goodsService.getGoods(result);

        return new GoodResult(ResultEnum.CATEGORY_SUCCESS.getErrno(),
                ResultEnum.CATEGORY_SUCCESS.getErrmsg(),
                goods.size(),
                result.getCatId(), goods
        );
    }

}
